/*
 * @Author: lin_zizhuo 2297304135@qq.com
 * @Date: 2023-11-20 14:33:37
 * @LastEditors: lin_zizhuo 2297304135@qq.com
 * @LastEditTime: 2023-11-20 17:08:01
 * @FilePath: /named_pipe/comm.hpp
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#include <iostream>
#include <string>
#include <cerrno>
#include <cstring>
#include <cstdlib>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/types.h>
#include "log.hpp"

using namespace std;

const char *fifo_name = "./mypipe";

enum SIZE
{
    buffer_size = 1024
};

enum Errno
{
    FIFO_CREATER_ERR = 1,
    FIFO_DELETE_ERR,
    FIFO_OPEN_ERR,
    FIFO_READ_ERR
};

class Init
{
public:
    Init()
    {
        int n = mkfifo(fifo_name, 0664);
        if (n == -1)
        {
            perror("mkfifo");
            exit(FIFO_CREATER_ERR);
        }
        cout << "mkfifo success!\n";
    }

    ~Init()
    {
        int n = unlink(fifo_name);
        if (n == -1)
        {
            perror("unlink fifo");
            exit(FIFO_DELETE_ERR);
        }
        cout << "mkfifo delete success!\n";
    }
};